<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<!--添加提报计划模态框-->
<div class="modal fade" id="modal-create">
    <div class="modal-dialog" style="width:1110px;">
        <div class="modal-content">
            <div class="modal-header">
                <button id="modal-create-close" type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">添加提报计划</h4>
            </div>
            <div class="modal-body" style="height: 600px;">
                <form id="createReportPlanForm" class="form-horizontal">
                    <div class="col-md-12">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">物料描述</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="rppMatDesc" autocomplete="off"
                                           placeholder="物料描述">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">项目编号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppProjectCode" autocomplete="off"
                                           placeholder="项目编号"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">项目名称</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppProjectName" autocomplete="off"
                                           placeholder="项目名称">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">项目数量</label>
                                <div class="col-sm-8">
                                    <input type="number" oninput="inputDecimalThree(this)" class="form-control"
                                           name="rppProjectNum" autocomplete="off"
                                           placeholder="项目数量">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">计划员</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="rppPlanner" title="">
                                        <option th:each="planner : ${planners}" th:value="${planner.empName}"
                                                th:text="${planner.empName}"></option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">计划号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppPlanNo" autocomplete="off"
                                           placeholder="计划号">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">数量</label>
                                <div class="col-sm-8">
                                    <input type="number" oninput="inputDecimalThree(this)" step="0.1"
                                           class="form-control" name="rppNum"
                                           autocomplete="off" placeholder="数量">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">单位</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppUnit" autocomplete="off"
                                           placeholder="单位">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">部分</label>
                                <div class="col-sm-8">
                                    <input type="text" maxlength="255" class="form-control" name="rppPart"
                                           autocomplete="off" placeholder="部分">
                                </div>
                            </div>
                        </div>


                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">型号/标准号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppStandardNo" autocomplete="off"
                                           placeholder="型号/标准号">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">品牌</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppBrand" autocomplete="off"
                                           placeholder="品牌">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">采购分类</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="rppTypeId" title="">
                                        <option th:each="type : ${categories}" th:value="${type.dicId}"
                                                th:text="${type.dicName}"></option>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6" id="createReportPlanFormRppUseStore">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">是否使用库存</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="rppUseStore" title="">
                                        <option value="0">否</option>
                                        <option value="1">是</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6" id="createReportPlanFormRppAssistType">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">外协类型</label>
                                <div class="col-sm-8">
                                    <select name="rppAssistType" class="form-control">
                                        <option value="">请选择</option>
                                        <option th:each="rppAssistType : ${rppAssistTypes}"
                                                th:value="${rppAssistType.name}"
                                                th:text="${rppAssistType.name}"></option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">提报人</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppDesigner" placeholder="提报人"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">联系方式</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppDesignerTel" placeholder="提报人联系方式">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6" id="createReportPlanFormRppDiagram">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">图号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppDiagram" autocomplete="off"
                                           placeholder="图号">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">备注</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppRemark" autocomplete="off"
                                           placeholder="备注">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">物料类别</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="rppMalType" title="">
                                        <option th:each="item : ${vwDictCommonList}" th:value="${item.name}"
                                                th:text="${item.name}"></option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">补录原因</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="rppSupReasons" autocomplete="off"
                                           placeholder="补录原因">
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
                <form id="uploadFileForm" class="form-horizontal">
                    <div class="col-md-12">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">附件上传</label>
                                <div class="col-sm-8">
                                    <input type="hidden" style="display: none" name="rppId">
                                    <input class="form-control" style="border: 0;padding-left: 0px;" type="file"
                                           name="file"/>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-create-report-plan">提交</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<!--导入提报计划模态框-->
<div class="modal fade" id="modal-import">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Excel信息导入</h4>
            </div>
            <div class="modal-body">
                <form id="importForm">
                    <div class="form-group">
                        <label>模版</label>
                        <a th:href="@{/file/补计划录入模板.xlsx}">点击下载</a>
                    </div>
                    <div class="form-group">
                        <label>上次导入错误数据</label>
                        <a id="download-error"
                           th:data-url="@{/files/{user}/error.xls(user=${session.user.account})}"
                           href="javascript:void(0);">点击下载</a>
                    </div>
                    <!--<div class="form-group">
                        <label for="yearMonth">生产日报上传年月份</label>
                        <input type="text" class="form-control col-md-3" id="yearMonth" name="yearMonth"
                               th:value="${#dates.format(date, 'yyyy-MM')}" readonly="readonly"/>
                    </div>-->
                    <div class="form-group">
                        <label>选择Excel文件并上传</label>
                        <input class="btn" type="file" multiple="multiple" name="file">
                        <p class="help-block">请按模板格式进行导入，信息与模板信息对应。</p>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button shiro:hasPermission="buy:planadd:add" id="btn-upload" type="button" class="btn btn-success">
                    <span class="Bold">上传</span>
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<!--修改提报计划模态框-->
<div class="modal fade" id="modal-edit">
    <div class="modal-dialog" style="width:1110px;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">修改提报计划</h4>
            </div>
            <div class="modal-body" style="height: 600px">
                <form id="editReportPlanForm" class="form-horizontal">
                    <input type="hidden" name="rppId">
                    <div class="col-md-12">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">物料描述</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="rppMatDesc" autocomplete="off"
                                           placeholder="物料描述">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">项目编号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppProjectCode" autocomplete="off"
                                           placeholder="项目编号">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">项目名称</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppProjectName" autocomplete="off"
                                           placeholder="项目名称">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">项目数量</label>
                                <div class="col-sm-8">
                                    <input type="number" oninput="inputDecimalThree(this)" class="form-control"
                                           name="rppProjectNum" autocomplete="off"
                                           placeholder="项目数量">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">计划员</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="rppPlanner" title="">
                                        <option th:each="planner : ${planners}" th:value="${planner.empName}"
                                                th:text="${planner.empName}"></option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">计划号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppPlanNo" autocomplete="off"
                                           placeholder="计划号">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">数量</label>
                                <div class="col-sm-8">
                                    <input type="number" oninput="inputDecimalThree(this)" step="0.1"
                                           class="form-control" name="rppNum"
                                           autocomplete="off" placeholder="数量">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">单位</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppUnit" autocomplete="off"
                                           placeholder="单位">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">部分</label>
                                <div class="col-sm-8">
                                    <input type="text" maxlength="255" class="form-control" name="rppPart"
                                           autocomplete="off" placeholder="部分">
                                </div>
                            </div>
                        </div>


                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">型号/标准号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppStandardNo" autocomplete="off"
                                           placeholder="型号/标准号">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">品牌</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppBrand" autocomplete="off"
                                           placeholder="品牌">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">采购分类</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="rppTypeId" title="">
                                        <option th:each="type : ${categories}" th:value="${type.dicId}"
                                                th:text="${type.dicName}"></option>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-6" id="editReportPlanFormRppUseStore">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">是否使用库存</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="rppUseStore" title="">
                                        <option value="0">否</option>
                                        <option value="1">是</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6" id="editReportPlanFormRppAssistType">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">外协类型</label>
                                <div class="col-sm-8">
                                    <select name="rppAssistType" class="form-control">
                                        <option value="">请选择</option>
                                        <option th:each="rppAssistType : ${rppAssistTypes}"
                                                th:value="${rppAssistType.name}"
                                                th:text="${rppAssistType.name}"></option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">提报人</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppDesigner" placeholder="提报人"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">联系方式</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppDesignerTel" placeholder="提报人联系方式">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6" id="editReportPlanFormRppDiagram">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">图号</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppDiagram" autocomplete="off"
                                           placeholder="图号">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">备注</label>
                                <div class="col-sm-8">
                                    <input type="text" class="form-control" name="rppRemark" autocomplete="off"
                                           placeholder="备注">
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">物料类别</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="rppMalType" title="">
                                        <option th:each="item : ${vwDictCommonList}" th:value="${item.name}"
                                                th:text="${item.name}"></option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">补录原因</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" name="rppSupReasons" autocomplete="off"
                                           placeholder="补录原因">
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
                <form id="uploadFileFormByEdit" class="form-horizontal">
                    <div class="col-md-12">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">附件上传</label>
                                <div class="col-sm-8">
                                    <input type="hidden" style="display: none" name="rppId">
                                    <input class="form-control" style="border: 0;padding-left: 0px;" type="file"
                                           name="file"/>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-edit-report-plan">提交</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<!--修改计划员模态框-->
<div class="modal fade" id="modal-edit-planner">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">修改计划员</h4>
            </div>
            <div class="modal-body">
                <form id="editPlannerForm" class="form-horizontal">
                    <input type="hidden" name="rppId">
                    <div class="col-md-12">
                        <div class="col-md-12">
                            <div class="form-group">
                                <label class="col-sm-4 control-label">计划员</label>
                                <div class="col-sm-8">
                                    <select class="form-control" name="rppPlanner" title="">
                                        <option th:each="planner : ${planners}" th:value="${planner.empName}"
                                                th:text="${planner.empName}"></option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" id="btn-edit-planner">提交</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>


<section class="content-header"><h1>补计划录入</h1></section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>物料描述</label>
                                    <input type="text" name="rppMatDesc" class="form-control" placeholder="请输入提报物料描述">
                                </div>
                                <div class="form-group">
                                    <label>项目编号</label>
                                    <input type="text" name="rppProjectCode" class="form-control" placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" name="rppProjectName" class="form-control" placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label>计划号</label>
                                    <input type="text" name="rppPlanNo" class="form-control" placeholder="请输入计划号">
                                </div>
                                <div class="form-group">
                                    <label>计划员</label>
                                    <input type="text" name="rppPlanner" class="form-control" placeholder="请输入计划员">
                                </div>
                                <div class="form-group">
                                    <label>类型</label>
                                    <select name="rppTypeId" class="form-control">
                                        <option value="" selected="selected">全部</option>
                                        <option th:each="type : ${categories}" th:value="${type.dicId}"
                                                th:text="${type.dicName}"></option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>单据状态</label>
                                    <select name="rppStatus" class="form-control">
                                        <option value="">全部</option>
                                        <option value="-1" selected="selected">未提交</option>
                                        <option value="2">已提交</option>
                                        <option value="-2">已删除</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>导入日期</label>
                                    <input type="text" class="form-control datepicker" name="startTime"
                                           readonly="readonly"/>
                                    <span> 至 </span>
                                    <input type="text" class="form-control datepicker" name="endTime"
                                           readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>

                        </div>
                    </form>
                    <div class="row" id="toolbar">
                        <div class="form-inline">
                            <a shiro:hasPermission="buy:planadd:add" href="javascript:void(0);"
                               class="btn btn-primary pull-right" style="margin-right: 10px"
                               onclick="openImportModal()">
                                <span class="Bold">导入</span>
                            </a>
                            <a shiro:hasPermission="buy:planadd:add" href="javascript:void(0);"
                               class="btn btn-info pull-right" style="margin-right: 10px" onclick="openCreateModal()">
                                <span class="Bold">添加</span>
                            </a>
                            <a shiro:hasPermission="buy:planadd:del" href="javascript:void(0);"
                               class="btn btn-danger pull-right" style="margin-right: 10px" onclick="deleteAll()">
                                <span class="Bold">全部删除</span>
                            </a>
                            <a shiro:hasPermission="buy:planadd:edit" href="javascript:void(0);"
                               class="btn btn-success pull-right" style="margin-right: 10px" onclick="commitAll()">
                                <span class="Bold">全部提交</span>
                            </a>

                        </div>
                    </div>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    /** 表格 */
    var table;
    var reportState = ['', '使用库存', '正常提报', '暂不提报', '甲供'];
    var projectState = ['无状态', '执行中', '未开始', '暂缓', '已完成','取消'];
    var colors = ['', "label-warning", "label-default", "label-danger", "label-success"];
    var colors1 = ['', "label-warning", "label-info", "label-primary"];
    var infoUrl = ctx + 'buy/editReportPlan/info/';
    /** 图片类型 */
    let imageFileType = ['BMP', 'JPG', 'PNG', 'TIF', 'GIF', 'PCX', 'TGA', 'EXIF', 'FPX', 'SVG', 'PSD', 'CDR', 'PCD', 'DXF', 'UFO', 'EPS', 'AI', 'RAW', 'WMF', 'WEBP'];

    /**
     * 添加提报计划面板控件显隐
     * */
    function controlDisplayByCreate() {
        let selectOptionText = $("#createReportPlanForm [name='rppTypeId'] option:selected").text();
        if(selectOptionText === '原材料'){
            $("#createReportPlanFormRppUseStore").show();
            $("#createReportPlanFormRppAssistType").hide();
            $("#createReportPlanFormRppDiagram").hide();
        }else if(selectOptionText === '外协件'){
            $("#createReportPlanFormRppUseStore").hide();
            $("#createReportPlanFormRppAssistType").show();
            $("#createReportPlanFormRppDiagram").show();
        }else{
            $("#createReportPlanFormRppUseStore").hide();
            $("#createReportPlanFormRppAssistType").hide();
            $("#createReportPlanFormRppDiagram").hide();
        }
    }



    /**
     * 修改提报计划面板控件显隐
     * */
    function controlDisplayByEdit() {
        let selectOptionText = $("#editReportPlanForm [name='rppTypeId'] option:selected").text();
        if(selectOptionText === '原材料'){
            $("#editReportPlanFormRppUseStore").show();
            $("#editReportPlanFormRppAssistType").hide();
            $("#editReportPlanFormRppDiagram").hide();
        }else if(selectOptionText === '外协件'){
            $("#editReportPlanFormRppUseStore").hide();
            $("#editReportPlanFormRppAssistType").show();
            $("#editReportPlanFormRppDiagram").show();
        }else{
            $("#editReportPlanFormRppUseStore").hide();
            $("#editReportPlanFormRppAssistType").hide();
            $("#editReportPlanFormRppDiagram").hide();
        }
    }

    /**
     * 文件查看
     * */
    function look(filePath) {
        let fileExtensions = filePath.substring(filePath.lastIndexOf(".") + 1);
        if (fileExtensions.toUpperCase() === 'PDF') {
            window.open([[@{/js/pdf/web/viewer.html}]]+'?file='+filePath,'PDF');
        } else {
            let isOPen = false;
            for (let i = 0; i < imageFileType.length; i++) {
                fileExtensions = fileExtensions.toUpperCase();
                if (fileExtensions == imageFileType[i]) {
                    isOPen = true;
                    window.open(filePath);
                    break;
                }
            }
            if (isOPen === false) {
                js.modal.warning("该文件格式是：" + fileExtensions + "文件无法预览!");
            }
        }
    }

    function inputDecimalThree(obj) {
        obj.value = obj.value.replace(/[^-\d.]/g, "");  //清除“数字”和“.”以外的字符
        obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
        obj.value = obj.value.replace(/\-{2,}-/g, "-"); //只保留第一个. 清除多余的
        obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d\d).*$/, '$1$2.$3');//只能输入两个小数
        if (obj.value.indexOf(".") < 0 && obj.value != "") {//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
            obj.value = obj.value;
        }
    }

    function checkProjectCodeNonExistent(code) {
        js.post({
            url: ctx + "buy/supplementaryReportPlanInput/checkProjectCodeNonExistent",
            data: {
                code: code
            },
            async: false,
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    return result.data;
                }
            }
        });
    }

    /** 打开导入模态框 */
    function openCreateModal() {
        js.modal.open("modal-create");
    }

    /** 打开导入模态框 */
    function openImportModal() {
        js.modal.open("modal-import");
    }

    /** 删除提报计划 */
    function deleteReportPlan(id) {
        js.confirmPost({
            content: "删除数据将无法恢复，确认删除吗？",
            url: ctx + "buy/supplementaryReportPlanInput/delete",
            data: {
                id: id
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }

    /** 批量删除提报计划 */
    function deleteAll() {
        var arr = js.table.selectColumns(table, "rppId");
        if (arr.length < 1) {
            js.modal.warning("请选择要删除的计划");
            return;
        }
        js.post({
            url: ctx + "buy/supplementaryReportPlanInput/deleteAll",
            data: {
                rppIds: js.table.selectColumns(table, "rppId")
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        })
    }

    /** 提交提报计划 */
    function commitReportPlan(id) {
        js.confirmPost({
            content: "确认提交吗？",
            url: ctx + "buy/supplementaryReportPlanInput/commit",
            data: {
                id: id
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        });
    }

    /** 批量提交提报计划 */
    function commitAll() {
        var arr = js.table.selectColumns(table, "rppId");
        if (arr.length < 1) {
            js.modal.warning("请选择要提交的计划");
            return;
        }
        js.post({
            url: ctx + "buy/supplementaryReportPlanInput/commitAll",
            data: {
                rppIds: js.table.selectColumns(table, "rppId")
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        })
    }

    /** 打开修改模态框 */
    function openEditReportPlanModal(row) {
        $("#editReportPlanForm").fillData(row);
        js.modal.open("modal-edit");
    }

    /** 打开修改计划员模态框 */
    function openEditPlannerModal(row) {
        $("#editPlannerForm").fillData(row);
        js.modal.open("modal-edit-planner");
    }

    $(function () {
        controlDisplayByCreate();
        controlDisplayByEdit();
        $("#modal-create-close").click(function () {
            $('#modal-create').modal("hide");
        })

        $("title").html($("title").html() + " —— 提报计划导入");
        /** 初始化表格 */
        table = js.table.init({
            url: ctx + "buy/supplementaryReportPlanInput/list",
            showColumns: false,
            showExport: false,
            pageSize: 300,
            paginationVAlign: 'both',
            columns: [
                {
                    checkbox: true,
                    width: '30px',
                    formatter: function (value, row, index) {
                        // 正常提报并且数据正常状态可以提交选择
                        if (row.rppStatus === -1) {
                            return {disabled: false}
                        } else {
                            return {disabled: true}
                        }
                    }
                },
                {
                    title: '序号', field: 'id', width: '50px',
                    formatter: function (value, row, index, field) {
                        return index + 1;
                    }
                },
                {title: "项目数量", field: 'rppProjectNum'},
                {title: "采购分类", field: 'rppTypes'},
                {title: "部分", field: 'rppPart',width: '60',
                    formatter: function (value, row, index) {
                        if(value===null){
                            value = '--';
                        }
                       return '<p style="word-wrap: break-word;width: 50px">' + value + '</p>';
                    }
                },
                {title: "物料分类", field: 'rppMalType'},
                {title: "物料描述", field: 'rppMatDesc',width: '130',
                    formatter: function (value, row, index) {
                        if(value===null){
                            value = '--';
                        }
                        return '<p style="word-wrap: break-word;width: 120px">' + value + '</p>';
                    }
                },
                {title: "数量", field: 'rppNum'},
                {title: "单位", field: 'rppUnit'},
                {title: "型号/标准号", field: 'rppStandardNo',width: '90',
                    formatter: function (value, row, index) {
                        if(value===null){
                            value = '--';
                        }
                        return '<p style="word-wrap: break-word;width: 80px">' + value + '</p>';
                    }
                },
                {title: "品牌", field: 'rppBrand',width: '90',
                    formatter: function (value, row, index) {
                        if(value===null){
                            value = '--';
                        }
                        return '<p style="word-wrap: break-word;width: 80px">' + value + '</p>';
                    }},
                {title: "备注", field: 'rppRemark', width: '60',
                    formatter: function (value, row, index) {
                        if(value===null){
                            value = '--';
                        }
                        return '<p style="word-wrap: break-word;width: 50px">' + value + '</p>';
                    }
                },
                {title: "项目编号", field: 'rppProjectCode'},
                {title: "项目名称", field: 'rppProjectName',width: '130',
                    formatter: function (value, row, index) {
                        if(value===null){
                            value = '--';
                        }
                        return '<p style="word-wrap: break-word;width: 120px">' + value + '</p>';
                    }
                },
                {title: "计划号", field: 'rppPlanNo',width: '90',
                    formatter: function (value, row, index) {
                        if(value===null){
                            value = '--';
                        }
                        return '<p style="word-wrap: break-word;width: 80px">' + value + '</p>';
                    }
                },
                {
                    title: "是否使<br>用库存", field: 'rppUseStore',
                    formatter: function (value, row, index) {
                        if (value === 0) {
                            return "否";
                        } else if (value === 1) {
                            return "是";
                        }else {
                            return "--";
                        }
                    }
                },
                {
                    title: "图号", field: 'rppDiagram',
                    formatter: function (value, row, index) {
                        if (value === '') {
                            return "";
                        } else {
                            return value;
                        }
                    }
                },
                {title: "外协类型", field: 'rppAssistType'},
                {title: "提报人", field: 'rppDesigner'},
                {title: "提报人联系方式", field: 'rppDesignerTel'},
                {title: "计划员", field: 'rppPlanner'},
                {title: "补录原因", field: 'rppSupReasons', width: '90px',
                    formatter: function (value, row, index) {
                        if(value===null){
                            value = '--';
                        }
                        return '<p style="word-wrap: break-word;width: 80px">' + value + '</p>';
                    }
                },
                {title: "提报日期", field: 'rppCreateTime', width: '90px'},
                {
                    title: "附件", field: 'rppExtendUrl', formatter: function (value, row, index) {
                        if (value != null) {
                            let elements = [];
                            if (hasP('buy:planadd:download')) {
                                // elements.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="look(\'' + value + '\')"><i class="fa  fa-search"></i> 查看</a> ');
                                elements.push('<a class="btn btn-primary btn-xs" href="' + value + '"><i class="glyphicon glyphicon-download-alt"></i> 下载</a> ');
                            }
                            return elements.join('');
                        } else {
                            return "";
                        }
                    }
                },
                {
                    title: "操作",
                    width: '110px',
                    formatter: function (value, row, index) {
                        var actions = [];
                        // 未提交状态
                        if (row.rppStatus === -1) {
                            if (hasP("buy:planadd:edit")) {
                                actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openEditReportPlanModal(' + js.jsonStringify(row) + ')"> 修改</a> ');
                                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="commitReportPlan(' + row.rppId + ')"> 提交</a> ');
                            }
                            if (hasP("buy:planadd:del")) {
                                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="deleteReportPlan(' + row.rppId + ')"> 删除</a> ');
                            }
                        } else if (row.rppStatus === 2) {
                            if (hasP("buy:planadd:edit")) {
                                actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="openEditPlannerModal(' + js.jsonStringify(row) + ')"> 修改</a> ');
                            }
                        }
                        return actions.join('');
                    }
                }
            ]
        });
        /** 表格搜索 */
        $("#btn-search").click(function () {
            js.table.search(table);
        });

        /**添加提报计划 采购分类改变事件*/
        $("#createReportPlanForm [name='rppTypeId']").change(function () {
            controlDisplayByCreate();
        })
        /**添加提报计划 采购分类改变事件*/
        $("#editReportPlanForm [name='rppTypeId']").change(function () {
            controlDisplayByEdit()();
        })


        /** 添加表单验证规则 */
        // js.validate.init("createReportPlanForm", {
        //     fields: {
        //         rppProjectCode: {
        //             validators: {
        //                 notEmpty: {message: '请输入项目编号'},
        //                 remote: {
        //                     url: ctx + "buy/supplementaryReportPlanInput/checkProjectCode",
        //                     message: '项目编号不存在',
        //                     delay: 500,
        //                     type: 'POST'
        //                 },
        //             }
        //         },
        //         rppProjectName: {validators: {notEmpty: {message: '请输入项目名称'}}},
        //         rppMatDesc: {validators: {notEmpty: {message: '请输入物料描述'}}},
        //         rppNum: {validators: {notEmpty: {message: '请输入数量'}}},
        //         rppUnit: {validators: {notEmpty: {message: '请输入单位'}}},
        //         rppSupReasons: {validators: {notEmpty: {message: '请输补录原因'}}},
        //     }
        // });
        /** 添加模态框隐藏事件，重置表单，重置验证 */
        js.modal.hideEvent("modal-create", function () {
            // js.validate.reset("createReportPlanForm");
            js.reset("createReportPlanForm");
        });
        /** 添加提报计划 */
        $("#btn-create-report-plan").click(function () {
            let validationPassed = true;
            let file = $("#uploadFileForm [name='file']").get(0).files[0];
            if ($("#createReportPlanForm [name='rppMatDesc']").val().trim() === '') {
                js.modal.warning("请填写物料描述");
                validationPassed = false;
            }
            if ($("#createReportPlanForm [name='rppProjectCode']").val().trim() === '') {
                js.modal.warning("请填写项目编号");
                validationPassed = false;
            }
            if ($("#createReportPlanForm [name='rppProjectName']").val().trim() === '') {
                js.modal.warning("请填写项目名称");
                validationPassed = false;
            }
            // if ($("#createReportPlanForm [name='rppProjectNum']").val().trim() === '') {
            //     js.modal.warning("请填写项目数量");
            //     validationPassed = false;
            // }
            if ($("#createReportPlanForm [name='rppPlanNo']").val().trim() === '') {
                js.modal.warning("请填写计划号");
                validationPassed = false;
            }
            if ($("#createReportPlanForm [name='rppNum']").val().trim() === '') {
                js.modal.warning("请填写数量");
                validationPassed = false;
            }
            if ($("#createReportPlanForm [name='rppUnit']").val().trim() === '') {
                js.modal.warning("请填写单位");
                validationPassed = false;
            }
            // if ($("#createReportPlanForm [name='rppPart']").val().trim() === '') {
            //     js.modal.warning("请填写部分");
            //     validationPassed = false;
            // }
            // if ($("#createReportPlanForm [name='rppDesigner']").val().trim() === '') {
            //     js.modal.warning("请填写提报人");
            //     validationPassed = false;
            // }
            // if ($("#createReportPlanForm [name='rppDesignerTel']").val().trim() === '') {
            //     js.modal.warning("请填写提报人联系方式");
            //     validationPassed = false;
            // }
            if ($("#createReportPlanForm [name='rppSupReasons']").val().trim() === '') {
                js.modal.warning("请填写补录原因");
                validationPassed = false;
            }
            if ($("#createReportPlanForm [name='rppTypeId'] option:selected").text().trim() === '外协件') {
                if ($("#createReportPlanForm [name='rppAssistType']").val().trim() === '') {
                    js.modal.warning("请填写外协类型");
                    validationPassed = false;
                }
                if ($("#createReportPlanForm [name='rppDiagram']").val().trim() === '') {
                    js.modal.warning("请填写外协图号");
                    validationPassed = false;
                }
            }

            if (file) {
                let sizeToMB = (file.size / 1024 / 1024).toFixed(2);
                if (sizeToMB > 100) {
                    js.modal.warning("上传文件大小不可超过100MB");
                    validationPassed = false;
                }
            }
            if (validationPassed) {
                js.post({
                    url: ctx + "buy/supplementaryReportPlanInput/checkProjectCodeNonExistent",
                    data: {
                        code: $("#createReportPlanForm [name='rppProjectCode']").val().trim()
                    },
                    async: false,
                    success: function (result) {
                        if (result.data === false) {
                            js.modal.warning("项目编号不存在");
                            return;
                        } else {
                            js.post({
                                url: ctx + "buy/supplementaryReportPlanInput/create",
                                data: $("#createReportPlanForm").serialize(),
                                success: function (result) {
                                    if (result.type === web_status.SUCCESS) {
                                        $("#uploadFileForm [name='rppId']").val(result.data);
                                        let file = $("#uploadFileForm [name='file']").get(0).files[0];
                                        if (file) {
                                            let sizeToMB = (file.size / 1024 / 1024).toFixed(2);
                                            if (sizeToMB <= 100) {
                                                js.post({
                                                    url: ctx + "buy/supplementaryReportPlanInput/uploadFile",
                                                    data: new FormData($("#uploadFileForm")[0]),
                                                    contentType: false,
                                                    processData: false,
                                                    success: function (result) {
                                                        if (result.type === web_status.SUCCESS) {
                                                            js.table.refresh(table);
                                                            $this.attr('disabled', false);
                                                        }
                                                    }
                                                });
                                            }
                                        }
                                        js.modal.success("添加成功！");
                                        js.table.refresh(table);
                                        js.modal.hide("modal-create");
                                    } else {
                                        js.modal.warning(result.msg);
                                    }
                                }
                            });
                        }
                    }
                });
            }
        });
        /** 导入表单验证规则 */
        js.validate.init("importForm", {
            fields: {
                file: {
                    validators: {
                        notEmpty: {message: '上传文件不能为空'},
                        file: {extension: 'xls,xlsx', message: '请选择excel文件'}
                    }
                }
            }
        });
        /** 导入模态框隐藏事件，重置表单，重置验证 */
        js.modal.hideEvent("modal-import", function () {
            js.validate.reset("importForm");
            js.reset("importForm");
        });
        /** 导入提报计划 */
        $("#btn-upload").click(function () {
            var $this = $(this);
            $this.attr('disabled', true);
            js.validSubmit({
                formId: "importForm",
                url: ctx + "buy/supplementaryReportPlanInput/import",
                data: new FormData($("#importForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        if (result.msg == '导入完成') {
                            js.modal.hide("modal-import");
                        }
                        js.table.refresh(table);
                        $this.attr('disabled', false);
                    }
                }
            });
        });


        /** 下载导入失败excel */
        $("#download-error").click(function () {
            var that = $(this);
            js.post({
                url: ctx + "buy/editReportPlan/exist",
                async: false,
                data: {
                    url: that.attr("data-url")
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        that.attr("href", that.attr("data-url") + "?timeStamp=" + new Date().getTime());
                    } else {
                        js.modal.warning("没有需要处理的文件");
                    }
                }
            });
        });


        /** 修改表单验证规则 */
        // js.validate.init("editReportPlanForm", {
        //     fields: {
        //         rppMatDesc: {validators: {notEmpty: {message: '请输入物料描述'}}},
        //         rppProjectName: {validators: {notEmpty: {message: '请输入项目名称'}}},
        //         rppNum: {validators: {notEmpty: {message: '请输入数量'}}},
        //         rppUnit: {validators: {notEmpty: {message: '请输入单位'}}}
        //     }
        // });
        /** 修改提报计划模态框隐藏事件， 重置表单，重置验证 */
        js.modal.hideEvent("modal-edit", function () {
            // js.validate.reset("editReportPlanForm");
            js.reset("editReportPlanForm");
        });
        /** 修改提报计划 */
        $("#btn-edit-report-plan").click(function () {
            let validationPassed = true;
            let file = $("#uploadFileFormByEdit [name='file']").get(0).files[0];
            if ($("#editReportPlanForm [name='rppMatDesc']").val().trim() === '') {
                js.modal.warning("请填写物料描述");
                validationPassed = false;
            }
            if ($("#editReportPlanForm [name='rppProjectCode']").val().trim() === '') {
                js.modal.warning("请填写项目编号");
                validationPassed = false;
            }
            if ($("#editReportPlanForm [name='rppProjectName']").val().trim() === '') {
                js.modal.warning("请填写项目名称");
                validationPassed = false;
            }
            // if ($("#editReportPlanForm [name='rppProjectNum']").val().trim() === '') {
            //     js.modal.warning("请填写项目数量");
            //     validationPassed = false;
            // }
            if ($("#editReportPlanForm [name='rppPlanNo']").val().trim() === '') {
                js.modal.warning("请填写计划号");
                validationPassed = false;
            }
            if ($("#editReportPlanForm [name='rppNum']").val().trim() === '') {
                js.modal.warning("请填写数量");
                validationPassed = false;
            }
            if ($("#editReportPlanForm [name='rppUnit']").val().trim() === '') {
                js.modal.warning("请填写单位");
                validationPassed = false;
            }
            // if ($("#editReportPlanForm [name='rppPart']").val().trim() === '') {
            //     js.modal.warning("请填写部分");
            //     validationPassed = false;
            // }
            // if ($("#editReportPlanForm [name='rppDesigner']").val().trim() === '') {
            //     js.modal.warning("请填写提报人");
            //     validationPassed = false;
            // }
            // if ($("#editReportPlanForm [name='rppDesignerTel']").val().trim() === '') {
            //     js.modal.warning("请填写提报人联系方式");
            //     validationPassed = false;
            // }
            if ($("#editReportPlanForm [name='rppSupReasons']").val().trim() === '') {
                js.modal.warning("请填写补录原因");
                validationPassed = false;
            }
            if ($("#editReportPlanForm [name='rppTypeId'] option:selected").text().trim() === '外协件') {
                if ($("#editReportPlanForm [name='rppAssistType']").val().trim() === '') {
                    js.modal.warning("请填写外协类型");
                    validationPassed = false;
                }
                if ($("#editReportPlanForm [name='rppDiagram']").val().trim() === '') {
                    js.modal.warning("请填写外协图号");
                    validationPassed = false;
                }
            }
            if (file) {
                let sizeToMB = (file.size / 1024 / 1024).toFixed(2);
                if (sizeToMB > 100) {
                    js.modal.warning("上传文件大小不可超过100MB");
                    validationPassed = false;
                }
            }
            if (validationPassed) {
                js.post({
                    url: ctx + "buy/supplementaryReportPlanInput/checkProjectCodeNonExistent",
                    data: {
                        code: $("#editReportPlanForm [name='rppProjectCode']").val().trim()
                    },
                    async: false,
                    success: function (result) {
                        if (result.data === false) {
                            js.modal.warning("项目编号不存在");
                            return;
                        } else {
                            js.post({
                                url: ctx + "buy/supplementaryReportPlanInput/edit",
                                data: $("#editReportPlanForm").serialize(),
                                success: function (result) {
                                    if (result.type === web_status.SUCCESS) {
                                        $("#uploadFileFormByEdit [name='rppId']").val($("#editReportPlanForm [name='rppId']").val());
                                        let file = $("#uploadFileFormByEdit [name='file']").get(0).files[0];
                                        if (file) {
                                            let sizeToMB = (file.size / 1024 / 1024).toFixed(2);
                                            if (sizeToMB <= 100) {
                                                js.post({
                                                    url: ctx + "buy/supplementaryReportPlanInput/uploadFile",
                                                    data: new FormData($("#uploadFileFormByEdit")[0]),
                                                    contentType: false,
                                                    processData: false,
                                                    success: function (result) {
                                                        if (result.type === web_status.SUCCESS) {
                                                            js.table.refresh(table);
                                                            $this.attr('disabled', false);
                                                        }
                                                    }
                                                });
                                            }
                                        }
                                        js.modal.success("修改成功！");
                                        js.table.refresh(table);
                                        js.modal.hide("modal-edit");
                                    } else {
                                        js.modal.warning(result.msg);
                                    }
                                }
                            });
                        }
                    }
                });
            }

            // js.validSubmit({
            //     formId: "editReportPlanForm",
            //     url: ctx + "buy/supplementaryReportPlanInput/edit",
            //     data: new FormData($("#editReportPlanForm")[0]),
            //     success: function (result) {
            //         if (result.type === web_status.SUCCESS) {
            //             js.modal.success(result.msg);
            //             js.table.refresh(table);
            //             js.modal.hide("modal-edit");
            //         } else {
            //             js.modal.warning(result.msg);
            //         }
            //     }
            // });
        });

        /** 修改计划员 */
        $("#btn-edit-planner").click(function () {
            js.submit({
                url: ctx + "buy/supplementaryReportPlanInput/edit",
                data: new FormData($("#editPlannerForm")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                        js.modal.hide("modal-edit-planner");
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            });
        });

    });

</script>
</body>
</html>
